package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.bomp.common.enums.RespCodeEnum;
import cc.rengu.igas.bomp.core.service.base.ManageService;
import cc.rengu.igas.bomp.facade.request.MPOSInstListQueryRequest;
import cc.rengu.igas.bomp.facade.response.MPOSInstListQueryResponse;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.StringUtil;

/**
 * 查询母POS机构列表
 * Created by moxm
 */
public class MPOSInstListQueryService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        MPOSInstListQueryRequest mPOSInstListQueryRequest = new MPOSInstListQueryRequest();
        ConvertUtil.convertOutput(mPOSInstListQueryRequest);
        return mPOSInstListQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        MPOSInstListQueryRequest mPOSInstListQueryRequest = (MPOSInstListQueryRequest) request;
        MPOSInstListQueryResponse mPOSInstListQueryResponse = new MPOSInstListQueryResponse();

        String instId = mPOSInstListQueryRequest.getHeader().getInstId();
        String userId = mPOSInstListQueryRequest.getUserId();
        String mposInstIndex = mPOSInstListQueryRequest.getMposInstIndex();
        /*必填性校验*/
        if (StringUtil.isEmptyOrNull(userId) || StringUtil.isEmptyOrNull(mposInstIndex)) {
            rglog.error("查询母POS机构列表交易必填性校验失败！");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
        /* 响应给请求方 */
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(mPOSInstListQueryResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        MPOSInstListQueryResponse mPOSInstListQueryResponse = (MPOSInstListQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(mPOSInstListQueryResponse);
    }
}
